
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteNewsLetterDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteNewsLetterDAL
    {
        #region  Properties
		 
		public static string FIELD_NEWSLETTERID = "NewsLetterID";  
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_FROM = "From";  
		public static string FIELD_TO = "To";  
		public static string FIELD_TITLE = "Title";  
		public static string FIELD_CONTENT = "Content";  
		public static string FIELD_DESCRIPTION = "Description";  
		public static string FIELD_CREATER = "Creater";  
		public static string FIELD_CREATEDATE = "CreateDate";  
		public static string FIELD_ISACTIVE = "IsActive";  
		public static string FIELD_ATRIBUTE1 = "Atribute1";  
		public static string FIELD_ATRIBUTE2 = "Atribute2";  
		public static string FIELD_ATRIBUTE3 = "Atribute3"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteNewsLetter
        /// </summary>
        /// <param name="NewsLetterID">Primary Keys</param>
        /// <returns>Collection of websiteNewsLetterInfo</returns>
        public static websiteNewsLetterInfo SelectOne(int NewsLetterID)
        {
            websiteNewsLetterInfo _websiteNewsLetterInfo = new websiteNewsLetterInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsLetterSelectOne", NewsLetterID);
                if (dr.Read())
                    setwebsiteNewsLetterInfo(dr, ref _websiteNewsLetterInfo);
                return _websiteNewsLetterInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        public static List<websiteNewsLetterInfo> SelectByLanguage(string LanguageCode)
        {
            List<websiteNewsLetterInfo> ltwebsiteNewsLetterInfo = new List<websiteNewsLetterInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsLetterSelectByLanguage", LanguageCode);
                setListwebsiteNewsLetterInfo(ref dr, ref ltwebsiteNewsLetterInfo);
                return ltwebsiteNewsLetterInfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }


        /// <summary>
        /// Select all websiteNewsLetter
        /// </summary>
        /// <returns>Collection of websiteNewsLetterInfo</returns>
        public static List<websiteNewsLetterInfo> SelectAll()
        {
            List<websiteNewsLetterInfo> lstwebsiteNewsLetter = new List<websiteNewsLetterInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsLetterSelectAll");
                setListwebsiteNewsLetterInfo(ref dr, ref lstwebsiteNewsLetter);
                return lstwebsiteNewsLetter;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteNewsLetternfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteNewsLetterInfo</returns>
        public static List<websiteNewsLetterInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteNewsLetterInfo> lstwebsiteNewsLetter = new List<websiteNewsLetterInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsLetterSelectByFilters");
                setListwebsiteNewsLetterInfo(ref dr, ref lstwebsiteNewsLetter);
                return lstwebsiteNewsLetter;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteNewsLetter
        /// </summary>
        /// <param name="websiteNewsLetterInfo">Entity of websiteNewsLetter</param>
        /// <returns>error code</returns>
        public static int Insert(websiteNewsLetterInfo _websiteNewsLetterInfo)
        {
           try
            {
                return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_mc_websiteNewsLetterInsert" 
											, _websiteNewsLetterInfo.LanguageCode											
											, _websiteNewsLetterInfo.Title
											, _websiteNewsLetterInfo.Content
											, _websiteNewsLetterInfo.Description
											, _websiteNewsLetterInfo.Creater
											));
                
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteNewsLetter
        /// </summary>
        /// <param name="websiteNewsLetterInfo">Entity of websiteNewsLetter</param>
        /// <returns>error code</returns>
        public static int Update(websiteNewsLetterInfo _websiteNewsLetterInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteNewsLetterUpdate"
											, _websiteNewsLetterInfo.NewsLetterID
											, _websiteNewsLetterInfo.LanguageCode											
											, _websiteNewsLetterInfo.Title
											, _websiteNewsLetterInfo.Content
											, _websiteNewsLetterInfo.Description
											, _websiteNewsLetterInfo.Creater																			
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="NewsLetterID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int NewsLetterID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteNewsLetterDelete", NewsLetterID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        public static int InsertResource(int NewsID, string Resources)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteNewsLetterInsertResource", NewsID, Resources);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteNewsLetterInfo(ref SqlDataReader dr, ref List<websiteNewsLetterInfo> lstwebsiteNewsLetter)
        {
            websiteNewsLetterInfo _websiteNewsLetterInfo = null;
            while (dr.Read())
            {
                _websiteNewsLetterInfo = new websiteNewsLetterInfo();
                setwebsiteNewsLetterInfo(dr, ref _websiteNewsLetterInfo);
                lstwebsiteNewsLetter.Add(_websiteNewsLetterInfo);
            }
        }

        private static void setwebsiteNewsLetterInfo(SqlDataReader dr, ref websiteNewsLetterInfo _websiteNewsLetterInfo)
        {
            _websiteNewsLetterInfo.NewsLetterID = dr[websiteNewsLetterDAL.FIELD_NEWSLETTERID] != DBNull.Value ? Convert.ToInt32(dr[websiteNewsLetterDAL.FIELD_NEWSLETTERID]) : 0;
			_websiteNewsLetterInfo.LanguageCode = dr[websiteNewsLetterDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_websiteNewsLetterInfo.From = dr[websiteNewsLetterDAL.FIELD_FROM] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_FROM]) : string.Empty;
			_websiteNewsLetterInfo.To = dr[websiteNewsLetterDAL.FIELD_TO] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_TO]) : string.Empty;
			_websiteNewsLetterInfo.Title = dr[websiteNewsLetterDAL.FIELD_TITLE] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_TITLE]) : string.Empty;
			_websiteNewsLetterInfo.Content = dr[websiteNewsLetterDAL.FIELD_CONTENT] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_CONTENT]) : null;
			_websiteNewsLetterInfo.Description = dr[websiteNewsLetterDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_DESCRIPTION]) : string.Empty;
			_websiteNewsLetterInfo.Creater = dr[websiteNewsLetterDAL.FIELD_CREATER] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_CREATER]) : string.Empty;
            _websiteNewsLetterInfo.CreateDate = dr[websiteNewsLetterDAL.FIELD_CREATEDATE] != DBNull.Value ? Convert.ToDateTime(dr[websiteNewsLetterDAL.FIELD_CREATEDATE]) : DateTime.Now;
			_websiteNewsLetterInfo.IsActive = dr[websiteNewsLetterDAL.FIELD_ISACTIVE] != DBNull.Value ? Convert.ToBoolean(dr[websiteNewsLetterDAL.FIELD_ISACTIVE]) : false;
			_websiteNewsLetterInfo.Atribute1 = dr[websiteNewsLetterDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_ATRIBUTE1]) : string.Empty;
			_websiteNewsLetterInfo.Atribute2 = dr[websiteNewsLetterDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_ATRIBUTE2]) : string.Empty;
			_websiteNewsLetterInfo.Atribute3 = dr[websiteNewsLetterDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteNewsLetterDAL.FIELD_ATRIBUTE3]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteNewsLetter]";

        #endregion
    }
}

		